package com.campus.api.config;

import com.campus.api.interceptor.UserInfoInterceptors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@ConditionalOnClass(DispatcherServlet.class)
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    private UserInfoInterceptors userInfoInterceptors;

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(userInfoInterceptors) //拦截器注册表中添加拦截器
                .addPathPatterns("/**") //指定拦截路径
                .excludePathPatterns(
                        "/doc.html/**",
                        "/v3/api-docs/**",
                        "/webjars/**",
                        "/auth/userLogin",
                        "/auth/userRegister"
                        );
    }
}
